<?php

namespace app\controller;

use app\BaseController;
use app\model\User;
use think\Request;

class UserLoginLogController extends BaseController {
	public function getLastLoginInfo(Request $request){
		$user_id = $request->param('id');
		$user = User::find($user_id);
		$time = $user->logs->last_login_time;
		$ip = $user->logs->last_login_ip;
		if($time && $ip){
			$data['time'] = $time;
			$data['ip'] = $ip;
			return json([
				'code' => 200,
				'msg' => '获取成功',
				'data' => $data
			]);
		}else{
			return json([
				'code' => 400,
				'msg' => '获取失败'
			],400);
		}
	}
	public function setLastLoginInfo(Request $request){
		$timestamp = $request->param('timestamp');
		$ip = $request->param('ip');
		$id = $request->param('id');
		$data = [
			'last_login_time' => $timestamp,
			'last_login_ip' => $ip
		];
		$user = User::find($id);
		if($user->logs()->save($data)){
			return json([
				'code' => 200,
				'msg' => '更新成功',
	
			]);
		}else{
			return json([
				'code' => 400,
				'msg' => '更新失败'
			],400);
		}
	}
}






?>